const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  
  data: {
    active: "record",
    nickname:"",
		avatar_image: "",
		agent_level: "",
    grand_amount: "",
    list:[],
    page:1,
    last_page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getData();
  },
  onChange(e){
    this.setData({active:e.detail.name});
    if(this.data.active == 'record'){
      this.getData(1)
    }else{
      this.getLevelData(1)
    }
  },
  getLevelData(page=1){
    app._postNetWork({
      url:app.getNetAddresss("plugin.subscription.frontend.modules.tier.controllers.records.index"),
      data:{page},
      success:res=>{
        if(res.data.result){
          let data = res.data.data;
          if(page = 1){
            this.setData({
              list:data.page_list.data,
              last_page:data.page_list.last_page,
              nickname:data.nickname,
              avatar_image: data.avatar_image,
              agent_level: data.agent_level,
              grand_amount: data.grand_amount,
            })
          }else{
            this.setData({
              list:this.data.list.concat(data.page_list.data),
              page:data.page_list.current_page,
            })
          }
        }else{
          app.tips(res.data.msg)
        }
      }
    })
  },
  getData(page=1){
    app._postNetWork({
      url:app.getNetAddresss("plugin.subscription.frontend.modules.bonus.controllers.records.index"),
      data:{page},
      success:res=>{
        if(res.data.result){
          let data = res.data.data;
          if(page = 1){
            this.setData({
              list:data.page_list.data,
              last_page:data.page_list.last_page,
              nickname:data.nickname,
              avatar_image: data.avatar_image,
              agent_level: data.agent_level,
              grand_amount: data.grand_amount,
            })
          }else{
            this.setData({
              list:this.data.list.concat(data.page_list.data),
              page:data.page_list.current_page,
            })
          }
        }else{
          app.tips(res.data.msg)
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    if(this.data.page>=this.data.last_page){
      return false;
    }
    if(this.data.active == 'record'){
      this.getData(this.data.page+1)
    }else{
      this.getLevelData(this.data.page+1)
    }
   
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})